<!DOCTYPE html>
<html lang="en">

{include file="Public/head"}

<body data-type="widgets">
<script src="/assets/js/theme.js"></script>

<div class="am-g tpl-g">

    {include file='Public:header'}
    {include file='Public:menu2'}



    <!-- 内容区域 -->
    <div class="tpl-content-wrapper" >
        <div class="row-content am-cf">
            <div class="row">

                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">新增</div>
                            <div class="widget-function am-fr">
                                <a href="javascript:;" class="am-icon-cog"></a>
                            </div>
                        </div>
                        <div class="panel-body" style="">
                            <ul class="nav nav-tabs">
                                <li class="active"><a href="#tab_tongyong" data-toggle="tab" aria-expanded="true">通用信息</a></li>
                                <li class=""><a href="#tab_goods_images" data-toggle="tab" aria-expanded="false">商品相册</a></li>
                                <li class=""><a href="#tab_goods_attr" data-toggle="tab" aria-expanded="false">商品属性</a></li>
                            </ul>
                            <!--表单数据-->
                            <form action="{:Url('/Goods/update')}" method="post" id="addEditGoodsForm" style="">

                                <!--通用信息-->
                                <div class="tab-content" style="">
                                    <div class="tab-pane active" id="tab_tongyong" style="">
                                        <table class="table table-bordered" style="">
                                            <tbody style="">
                                            <tr>
                                                <td>商品名称:</td>
                                                <td>
                                                    <input type="text" value="{$list.goods_name}" name="goods_name" class="form-control" style="width:550px;">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>商品简介:</td>
                                                <td>
                                                    <textarea rows="3" cols="80" name="goods_remark">{$list.goods_remark}</textarea>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>商品货号</td>
                                                <td>
                                                    <input type="text" value="{$list.goods_sn}" name="goods_sn" class="form-control" style="width:350px;">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>SPU</td>
                                                <td>
                                                    <input type="text" value="{$list.spu}" name="spu" class="form-control" style="width:350px;">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>SKU</td>
                                                <td>
                                                    <input type="text" value="{$list.sku}" name="goods_sku" class="form-control" style="width:350px;">
                                                    <span id="sku" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>商品分类:</td>
                                                <td>
                                                    <div class="col-xs-3">
                                                        <select name="cat_id" id="cat_id" onchange="get_category(this.value,'cat_id_2','0');" class="form-control" style="width:250px;margin-left:-15px;">
                                                            <option value="0">请选择商品分类</option>
                                                            {foreach name="classify" key="k" item="v"}
                                                            <option value="{$v.id}" {if condition="$v.id eq $list.cat_id"} selected="selected" {/if}>{$v.name}</option>
                                                            {/foreach}
                                                        </select>
                                                    </div>
                                                    <div class="col-xs-3">
                                                        <select name="cat_id_2" id="cat_id_2"  class="form-control" style="width:250px;margin-left:-15px;">
                                                            <option value="0">请选择商品分类</option>
                                                        </select>
                                                    </div>
                                                </td>
                                            </tr>


                                            <tr>
                                                <td>商品品牌:</td>
                                                <td>
                                                    <select name="brand_id" id="brand_id" class="form-control" style="width:250px;">
                                                        <option value="">所有品牌</option>
                                                        {foreach name="brand" key="k" item="v"}
                                                        <option value="{$k}" {if condition="$k eq $list.brand_id"} selected="selected" {/if}>{$v}</option>
                                                        {/foreach}
                                                    </select>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>本店售价:</td>
                                                <td>
                                                    <input type="text" value="{$list.shop_price}" name="shop_price" class="form-control" style="width:150px;" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                                    <span id="err_shop_price" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>市场价:</td>
                                                <td>
                                                    <input type="text" value="{$list.market_price}" name="market_price" class="form-control" style="width:150px;">
                                                    <span id="err_market_price" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>成本价:</td>
                                                <td>
                                                    <input type="text" value="{$list.cost_price}" name="cost_price" class="form-control" style="width:150px;">
                                                    <span id="err_cost_price" style="color:#F00; display:none"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>佣金:</td>
                                                <td>
                                                    <input type="text" value="{$list.commission}" name="commission" class="form-control" style="width:150px;">
                                                    用于分销的分成金额
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>上传商品图片:</td>
                                                <td>
                                                    <input type="file" value="{$list.original_img}" name="image1" id="image1" onchange="img(this)"  accept="image/jpg,image/jpeg,image/png,image/PNG" class="form-control large" style="width:500px;margin-top:10px; "/>
                                                    {if condition="$list.original_img eq null"}
                                                    <img src="" id="img2"style="width: 200px;height: 100px;text-align: center;display: none"/>
                                                    {else/}
                                                    <img src="" id="img2"style="width: 200px;height: 100px;text-align: center"/>
                                                    {/if}
                                                    <span id="err_original_img" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>商品重量:</td>
                                                <td>
                                                    <input type="text" class="form-control" style="width:150px;" value="{$list.weight}" name="weight" >
                                                    &nbsp;克 (以克为单位)
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>是否包邮:</td>
                                                <td>
                                                    {if condition="($list.is_free_shipping eq 1) or ($list.is_free_shipping eq NULL)"}
                                                    是: <input checked="checked" type="radio" name="is_free_shipping" value="1">
                                                    否:<input type="radio" name="is_free_shipping" value="0">
                                                    {else /}
                                                    是:<input type="radio" name="is_free_shipping" value="1">
                                                    否:<input checked="checked" type="radio" name="is_free_shipping" value="0">
                                                    {/if}
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>库存数量:</td>
                                                <td>
                                                    <input type="text" value="{$list.store_count}" class="form-control" style="width:150px;" name="goods_store_count">
                                                    <span id="err_store_count" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>赠送积分:</td>
                                                <td>
                                                    <input type="text" class="form-control" style="width:150px;" value="{$list.give_integral}" name="give_integral">
                                                    <span id="err_give_integral" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>兑换积分:</td>
                                                <td>
                                                    <input type="text" class="form-control" style="width:150px;" value="{$list.exchange_integral}" name="exchange_integral" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')">
                                                    <span id="err_exchange_integral" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>商品关键词:</td>
                                                <td>
                                                    <input type="text" class="form-control" style="width:550px;" value="{$list.keywords}" name="keywords">
                                                    <span id="err_keywords" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            <tr style="">
                                                <td>商品详情描述:</td>
                                                <td width="85%" style="">
                                                    <textarea  class="container" name="container"  rows="5" id="container" title=""  >{$list.goods_content}</textarea>
                                                    <span id="err_goods_content" style="color:#F00; display:none;"></span>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>

                                    </div>
                                    <!--其他信息-->

                                    <!-- 商品相册-->
                                    <div class="tab-pane " id="tab_goods_images">
                                        <table class="table table-bordered">
                                            <tbody>
                                            <tr>
                                                <td>
                                                    <div class="goods_xc" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
                                                        <input type="hidden" name="goods_images[]" value="">
                                                        <div class="am-u-sm-8" >
                                                            <input type="file" value="" name="image" id="image" onchange="imgPreview(this)"  accept="image/jpg,image/jpeg,image/png,image/PNG" class="form-control large" style="width:500px;margin-top:10px; "/>
                                                            <img src="{$imgpa.image_url}" id="img3"style="width: 200px;height: 100px;text-align: center;"/>
                                                            <br>
                                                            <a href="javascript:void(0)">&nbsp;&nbsp;</a>
                                                        </div>
                                                </td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                    <!--商品相册-->
                                    <!-- 商品属性-->
                                    <div class="tab-pane " id="tab_goods_attr">
                                        <table class="table table-bordered" id="goods_attr_table">
                                            <tbody><tr>
                                                <td>所选商品属性:</td>
                                                <td>

                                                    <select name="goods_type" id="goods_type" class="form-control" style="width:250px;">
                                                        <option value="0">选择商品属性</option>
                                                        {foreach $attr as $k=>$v}
                                                        <option value="{$v.id}" {if condition="$cat3 eq $v.id"} selected="selected" {/if}>{$v.name}</option>
                                                        {/foreach}
                                                    </select>

                                                </td>
                                            </tr>
                                            <tr class="attr_321"><td> 属性名称</td> <td><input type="text" size="80" value="{$cat1}" name="brand_name"></td>
                                            <tr class="attr_321"><td> 品牌</td> <td><input type="text" size="80" value="{$cat2.name}" name="brand"></td>
                                            </tbody>

                                        </table>

                                    </div>
                                    <!-- 商品属性-->

                                </div>
                                <div class="pull-right">
                                    <input type="hidden" name="goods_id" value="{$list.goods_id}">
                                    <input type="hidden" name="brand_id" value="{$cat2.brand_id}">
                                    <button class="btn btn-primary" onclick="ajax_submit_form('addEditGoodsForm','{:Url('/Admin/Goods/update')}');" title="" data-toggle="tooltip" type="button" data-original-title="保存">保存</button>
                                </div></form><!--表单数据-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>

<script>
    function imgPreview(fileDom) {
        //判断是否支持FileReader
        if(window.FileReader) {
            var reader = new FileReader();
        } else {
            alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
        }
        //获取文件
        var file = fileDom.files[0];
        var imageType = /^image\//;
        //是否是图片
        if(!imageType.test(file.type)) {
            alert("请选择图片！");
            return;
        }
        //读取完成
        reader.onload = function(e) {
            //获取图片dom
            var img = document.getElementById("img3");
            console.log(img)
            //图片路径设置为读取的图片
            img.src = e.target.result;
            $("#img3").css("display", "block")
        };
        reader.readAsDataURL(file);
    }
    function img(fileDom) {
        //判断是否支持FileReader
        if(window.FileReader) {
            var reader = new FileReader();
        } else {
            alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
        }
        //获取文件
        var file = fileDom.files[0];
        var imageType = /^image\//;
        //是否是图片
        if(!imageType.test(file.type)) {
            alert("请选择图片！");
            return;
        }
        //读取完成
        reader.onload = function(e) {
            //获取图片dom
            var img = document.getElementById("img2");
            console.log(img)
            //图片路径设置为读取的图片
            img.src = e.target.result;
            $("#img2").css("display", "block")
        };
        reader.readAsDataURL(file);
    }
    $(function () {
        //点击切换不同的输入
        $('[data-toggle="tab"]').click(function () {
            // console.log($(this).attr('href'));
            $('[data-toggle="tab"]').parent().removeClass('active');//样式初始化
            $(this).parent().addClass('active');//选中改变样式
            $('[data-toggle="tab"]').attr('aria-expanded',false);//属性初始化
            $(this).attr('aria-expanded',true);//选中属性变true
            // $('[data-toggle="tab"]').
            $(".tab-pane").removeClass('active');//详情初始化
            $($(this).attr('href')).addClass('active');//选中打开详情
        })
    });
    window.onload = function(){
            get_category($("#cat_id").val(),'cat_id',{$cat.parent_id});
        }
    //提交
    function roleSubmit(){
        var form=document.getElementById("roleform");
        var formData=new FormData(form);
        $.ajax({
            url:"{:Url('addData')}",
            type:'POST',
            data:formData,
            async: false,
            cache: false,
            contentType: false, //不设置内容类型
            processData: false, //不处理数据
            success:function(res){
                console.log(res);
                if (res.code != 200) {
                    layer.msg(res.msg, {shade: 0.5, time: 2000,icon: 2});
                    return false;
                }
                layer.msg(res.msg, {shade: 0.5, time: 2000, icon: 1}, function(){
                    window.location.href=document.referrer;

                });
            }
        });
    }
</script>
<script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    //var ue = UE.getEditor('container');
    var ue = UE.getEditor('container', {
        autoHeightEnabled:false,
        initialFrameHeight:420
    });
</script>
<script src="/js/global.js"></script>
<script src="/js/myFormValidation.js"></script>
<script src="/js/myAjax.js"></script>
<script src="http://cdn.bootcss.com/amazeui/2.7.2/js/amazeui.min.js"></script>
<script src="/assets/js/amazeui.datatables.min.js"></script>
<script src="/assets/js/dataTables.responsive.min.js"></script>
<script src="/assets/js/app.js"></script>
{include file='Public:script'}
</html>